package com.example.carRental.controller;

import com.example.carRental.entity.User;
import com.example.carRental.service.LoginService;
import com.example.carRental.utils.R;
import com.example.carRental.utils.RD;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 92307
 * @version 1.0
 * @time 2022/3/20
 */

@RestController
public class LoginController {

    @Resource
    private LoginService loginService;

    @PostMapping("/user/login")
    public RD login(@RequestBody User user){
        System.out.println("登录进入了");
        return loginService.login(user);
    }

    @PostMapping("/user/logout")
    public R logout(){
        return loginService.logout();
    }

    @GetMapping("/user/info")
    public RD info(){
        System.out.println("info进来了");
        return RD.success().putData("roles",User.getUserInfo()).putData("avatar","http://localhost:8080/charterer/getImage?filePath=AziLWGy7X6dj7YIOEa7MvDYlLgYvHaFb.jpg");
    }

    @PostMapping("/hello")
    @PreAuthorize("hasAuthority('user')")
    public String hello(){
        return "hello";
    }

}
